<?php
/**
 * 广告添加
 *
 * @version        $Id: ad_add.php 1 8:26 2010年7月12日Z tianya $
 * @package        DedeCMS.Administrator
 * @copyright      Copyright (c) 2007 - 2010, DesDev, Inc.
 * @license        http://help.dedecms.com/usersguide/license.html
 * @link           http://www.dedecms.com
 */
 
require(dirname(__FILE__)."/config.php");
require_once DEDEINC."/typelink.class.php";
require_once(DEDEADMIN.'/inc/inc_web.class.php');
require_once(DEDEADMIN.'/inc/inc_catalog_options.php');
if(empty($dopost)) $dopost = "";
$web_id = preg_replace("#[^0-9]#", '', $web_id);
$ENV_GOBACK_URL = empty($_COOKIE['ENV_GOBACK_URL']) ? "ad_main.php" : $_COOKIE['ENV_GOBACK_URL'];

if($dopost=='delete')
{

	 $dsql->ExecuteNoneQuery("DELETE FROM `#@__web` WHERE web_id='$web_id' ");
	 ShowMsg("成功删除一则广告代码！", $ENV_GOBACK_URL);
	 exit();
}
else if($dopost=="editsave")
{
	$path="../uploads/web/"; //上传路径 
	//允许上传的文件格式
	$tp = array("image/gif","image/pjpeg","image/png","image/jpeg");
	if(!is_dir($path))
	{
		//检查是否有该文件夹，如果没有就创建，并给予最高权限
			mkdir("$path", 0777);
	}//END IF
	//不同路径
	if (!empty($big_img2)){
		//检查上传文件是否在允许上传的类型
		if(!in_array($_FILES["big_img2"]["type"],$tp))
		{
			ShowMsg("格式不对!","web_add.php");
			exit();
		}//END IF
		
		$flag1 = false;
		if($_FILES["big_img2"]["name"])
		{
			$file1=pathinfo($_FILES["big_img2"]["name"]);
			$ext = $file1['extension'];
			$big_img = $path.'big_'.time().rand(10000,100000).'.'.$ext;
			$flag1=TRUE;
		}//END IF
		if($flag1) move_uploaded_file($_FILES["big_img2"]["tmp_name"],$big_img);
	}
	//不同路径
	if (!empty($small_img2)){

		//检查上传文件是否在允许上传的类型
		if(!in_array($_FILES["small_img2"]["type"],$tp))
		{
			ShowMsg("格式不对!",$ENV_GOBACK_URL);
			exit();
		}//END IF
		
		$flag2 = false;
		if($_FILES["small_img2"]["name"])
		{
			$file1=pathinfo($_FILES["small_img2"]["name"]);
			$ext = $file1['extension'];
			$small_img = $path.'small_'.time().rand(10000,100000).'.'.$ext;
			$flag2=TRUE;
		}//END IF
		if($flag2) move_uploaded_file($_FILES["small_img2"]["tmp_name"],$small_img);	
	}
	
	if (!$arctype_id){
			$arctype_id=0;
	}
	$big_img = str_replace("..", "", $big_img);
	$small_img = str_replace("..", "", $small_img);
    $query = "update #@__web
    set `link` = '$link',
    `title` = '$title',
    `remark` = '$remark',
    `big_img` = '$big_img',
    `small_img` = '$small_img',
    `sort` = '$sort',
    `arctype_id` = '$arctype_id',
    `position` = '$position' 
     where web_id=".$web_id;
	$dsql->ExecuteNoneQuery($query);
    ShowMsg("成功修改一个广告！",$ENV_GOBACK_URL);
    exit();
}
$channelid = empty($channelid) ? 0 : intval($channelid);
$cid = empty($cid) ? 0 : intval($cid);
$row = $dsql->GetOne("SELECT * FROM `#@__web` WHERE web_id='$web_id'");

include DedeInclude('templets/web_edit.htm');
?>